<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        /* 把子元素设置成为inline-block 然后父盒子设置text-align:center */
        .m1 {
            width: 300px;
            height: 300px;
            border: 1px solid red;
            text-align: center;
        }

        .m2 {
            width: 200px;
            height: 200px;
            border: 1px solid blue;
            margin: 0 auto;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="m1">
        <div class="m2"></div>
    </div>
</body>

</html>